//
//  UserDefaults.m
//  XKJY
//
//  Created by xiaokang on 2017/3/15.
//  Copyright © 2017年 xiaokang100. All rights reserved.
//

#import "UserDefaults.h"

@implementation UserDefaults

+ (BOOL)setObjectWithData:(id)data {
    
    BOOL result = YES;
    if (![data isKindOfClass:[NSDictionary class]]) {
        return NO;
    }
    NSArray *keys = [data allKeys];
    for (NSObject *key in keys) {
        NSObject *obj = data[key];
        if (obj == [NSNull null]) {
            result = NO;
            continue;
        }
        [[NSUserDefaults standardUserDefaults] setObject:obj forKey:[NSString stringWithFormat:@"user_%@",key]];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    
    return result;
}

+ (BOOL)setObject:(id)object withKey:(NSString *)key {
    if (object == [NSNull null]) {
        return NO;
    }
    [[NSUserDefaults standardUserDefaults] setObject:object forKey:[NSString stringWithFormat:@"user_%@",key]];
    [[NSUserDefaults standardUserDefaults] synchronize];
    return YES;
}

+ (NSString *)objectWithKey:(NSString *)key {
    id obj = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"user_%@",key]];
    if (obj) {
        return [NSString stringWithFormat:@"%@",obj];
    }else {
        return @"";
    }
}

+ (void)logoutAndRemoveUserDefaults {
    
    // 移除用户信息
//    [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]];
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults removeObjectForKey:@"wopnum"];
    [userDefaults removeObjectForKey:@"wopincome"];
    [userDefaults removeObjectForKey:@"apptoken"];
    [userDefaults removeObjectForKey:@"level"];
    [userDefaults removeObjectForKey:@"nick"];
    [userDefaults removeObjectForKey:@"member_points"];
    [userDefaults removeObjectForKey:@"trade_fee"];
    [userDefaults removeObjectForKey:@"name"];
    [userDefaults removeObjectForKey:@"status"];
    [userDefaults removeObjectForKey:@"pay_style"];
    [userDefaults removeObjectForKey:@"ip"];
    [userDefaults removeObjectForKey:@"t"];
    [userDefaults removeObjectForKey:@"wopforzen_num"];
    [userDefaults removeObjectForKey:@"rmbnum"];
    [userDefaults removeObjectForKey:@"wopnum"];
    [userDefaults removeObjectForKey:@"rmbforzen_num"];
    [userDefaults removeObjectForKey:@"pid"];
    
}



@end













